Skip to content

gh-75572: Speed up test_xpickle#144393

Merged
serhiy-storchaka merged 2 commits into
python:mainfrom
serhiy-storchaka:test_xpickle-speedup
Feb 2, 2026
Merged

gh-75572: Speed up test_xpickle#144393
serhiy-storchaka merged 2 commits into
python:mainfrom
serhiy-storchaka:test_xpickle-speedup

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Feb 2, 2026

Copy link
Copy Markdown
Member

Run a long living subprocess which handles multiple requests instead of running a new subprocess for each request.

Run a long living subprocess which handles multiple requests instead of
running a new subprocess for each request.
@serhiy-storchaka serhiy-storchaka added tests Tests in the Lib/test dir skip news needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Feb 2, 2026
Comment thread Lib/test/test_xpickle.py Outdated
worker = cls.worker
if worker is None:
target = os.path.join(os.path.dirname(__file__), 'xpickle_worker.py')
worker = subprocess.Popen([*python, target],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not calling start_worker() here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this is a remnant. I was not sure whether it is worth to move this code out into a method.

Comment thread Lib/test/test_xpickle.py Outdated
cls.worker = worker

@classmethod
def close_worker(cls):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"stop_worker()" name would be better to have start/stop_worker methods.

Comment thread Lib/test/test_xpickle.py
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
# For windows bpo-17023.
shell=is_windows)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use text=True to fix this code below:

            _, stderr = worker.communicate()
            raise RuntimeError(stderr)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we do binary IO for stdin/stdout in normal case.

This code is only for troubleshooting. It is not executed when the tests pass.

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

./python -m test test_xpickle -u xpickle,cpu -v command takes:

  • main branch: 24 min 38 sec
  • this PR: 1 min 24 sec

Well, it's much faster with this PR :-)

Note: I measured timings on a debug build (gcc -Og).

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@serhiy-storchaka

Copy link
Copy Markdown
Member Author

Note that you can run it only for the selected version, e.g. xpython=3.13. In debug build it is about 50% slower.

@serhiy-storchaka serhiy-storchaka merged commit 29acc08 into python:main Feb 2, 2026
49 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 2, 2026
Run a long living subprocess which handles multiple requests instead of
running a new subprocess for each request.
(cherry picked from commit 29acc08)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 2, 2026
Run a long living subprocess which handles multiple requests instead of
running a new subprocess for each request.
(cherry picked from commit 29acc08)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@bedevere-app

bedevere-app Bot commented Feb 2, 2026

Copy link
Copy Markdown

GH-144403 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Feb 2, 2026
@serhiy-storchaka serhiy-storchaka deleted the test_xpickle-speedup branch February 2, 2026 18:00
@bedevere-app

bedevere-app Bot commented Feb 2, 2026

Copy link
Copy Markdown

GH-144404 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Feb 2, 2026
serhiy-storchaka added a commit that referenced this pull request Feb 3, 2026
Run a long living subprocess which handles multiple requests instead of
running a new subprocess for each request.
(cherry picked from commit 29acc08)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka added a commit that referenced this pull request Feb 3, 2026
Run a long living subprocess which handles multiple requests instead of
running a new subprocess for each request.
(cherry picked from commit 29acc08)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@bedevere-bot

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 Windows Server 2022 NoGIL 3.13 (tier-1) has failed when building commit 9d76689.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1488/builds/1904) and take a look at the build logs.
  4. Check if the failure is related to this commit (9d76689) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1488/builds/1904

Failed tests:

  • test_launcher

Failed subtests:

  • test_search_major_2 - test.test_launcher.TestLauncher.test_search_major_2
  • test_search_major_3 - test.test_launcher.TestLauncher.test_search_major_3

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "C:\Users\Administrator\buildarea\3.13.itamaro-win64-srv-22-aws.x64.nogil\build\Lib\test\test_launcher.py", line 445, in test_search_major_3
    self.assertEqual("PythonCore", data["env.company"])
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 'PythonCore' != 'PythonTestSuite'
- PythonCore
+ PythonTestSuite


Traceback (most recent call last):
  File "C:\Users\Administrator\buildarea\3.13.itamaro-win64-srv-22-aws.x64.nogil\build\Lib\test\test_launcher.py", line 465, in test_search_major_2
    self.assertEqual("PythonCore", data["env.company"])
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 'PythonCore' != 'PythonTestSuite'
- PythonCore
+ PythonTestSuite

@bedevere-bot

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 Debian root 3.13 (tier-1) has failed when building commit 9d76689.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1441/builds/1761) and take a look at the build logs.
  4. Check if the failure is related to this commit (9d76689) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1441/builds/1761

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/root/buildarea/3.13.angelico-debian-amd64/build/Lib/test/support/__init__.py", line 856, in gc_collect
    gc.collect()
ResourceWarning: unclosed file <_io.FileIO name=13 mode='wb' closefd=True>

Aniketsy pushed a commit to Aniketsy/cpython that referenced this pull request Feb 3, 2026
Run a long living subprocess which handles multiple requests instead of
running a new subprocess for each request.
thunder-coding pushed a commit to thunder-coding/cpython that referenced this pull request Feb 15, 2026
Run a long living subprocess which handles multiple requests instead of
running a new subprocess for each request.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants